#include <vcl.h>
#include <delayimp.h>
#pragma hdrstop

#include "CAlexMaker.h"
#include "uDocument.h"
#include "uStyles.h"
#include "GenEtatVer.h"

#include "uVisualise.h"

#include <delayimp.h>
#pragma package(smart_init)
#pragma link "etat.lib"

#define MODULE_TAG MODULE_TAG_CALEXMAKER

#define DEB_TAG_DOC      50
#define DEB_TAG_ETAT    100
#define DEB_TAG_BANDE   200
#define DEB_TAG_CHAMP   300
#define DEB_TAG_TABLEAU 400
//---------------------------------------------------------------------------
// ValidCtrCheck est utilisé est utilisé pour être sûr que les composants créés n'ont
// aucune fonction virtuelle pure.
//
bool       gVersionDeDemonstration = false;
bool       g_EtatInitialise = false;
bool       gGestionEnvoiGED = true;
bool       gImpressionGroupeeGED = false;
static inline void ValidCtrCheck(CAlexMaker *)
{
    new CAlexMaker(NULL);
}
//---------------------------------------------------------------------------
namespace Calexmaker
{
    void __fastcall PACKAGE Register()
    {
         TComponentClass classes[1] = {__classid(CAlexMaker)};
         RegisterComponents("AlexMaker", classes, 0);
    }
}
//---------------------------------------------------------------------------
__fastcall CAlexMaker::CAlexMaker(TComponent* Owner)
    : TComponent(Owner)
{
    try{
    m_MargeGaucheMm = USHRT_MAX;
    m_MargeHautMm   = USHRT_MAX;
    m_MargeDroitMm  = USHRT_MAX;
    m_MargeBasMm    = USHRT_MAX;
    m_MargeHorsEnteteMm = USHRT_MAX;
    m_MargeHorsPiedMm   = USHRT_MAX;
    m_DocNameList = new TStringList();
    m_Owner   = Owner;
    m_NbCopies = 1;
    m_ImpressionRonde = true;
    WantColor             = false;
    WantProgress          = true;
    WantChoixImprimante   = true;
    m_Visu = NULL;
    m_Langue = 0;

    m_ShowNbCopies = true;
    m_TypeImpr = ti_Visu;
    m_bPrepareLaVisu = false;

    f_OnSQLParams = NULL;
    f_OnBDInitialized = NULL;

    f_OnStartDoc = NULL;
    f_OnEndDoc = NULL;

    f_OnStartEtat = NULL;
    f_OnEndEtat = NULL;

    f_OnFirstBandeEtat = NULL;
    f_OnFirstPageFooter = NULL;
    f_OnFirstPageHeader = NULL;
    f_OnPageFooter = NULL;
    f_OnPageHeader = NULL;

    f_OnBandeDebut = NULL;
    f_OnBandeDebutSection = NULL;
    f_OnBandeDebutColonne = NULL;
    f_OnBandeReportDebutDePage = NULL;
    f_OnBandeDetail = NULL;
    f_OnBandeUtilisateur = NULL;
    f_OnBandeReportFinDePage = NULL;
    f_OnBandeFinColonne = NULL;
    f_OnBandeFinSection = NULL;
    f_OnBandeFin = NULL;
    f_OnAfterFirstBandeInit = NULL;
    f_OnSautDePage = NULL;
    f_OnErreur = NULL;
    f_OnVariable = NULL;

    f_OnChamp = NULL;
    f_OnTableau = NULL;

    DocumentsCharges = new TStringList();
    }CATCH_EXCEPTION( TAG( 1))
}
//---------------------------------------------------------------------------
__fastcall CAlexMaker::~CAlexMaker()
{
    try{
    if( DocumentsCharges)
    {
        while( DocumentsCharges->Count)
        {
            DeleteTDocument( (TDocument*)(DocumentsCharges->Objects[0]));
            DocumentsCharges->Delete(0);
        }
        delete DocumentsCharges;
    }
    DeInit();
    if( m_DocNameList) delete m_DocNameList;
    if( g_EtatInitialise)
    {
        EtatUnInitialize();
        g_EtatInitialise = false;
    }
    }CATCH_EXCEPTION( TAG( 2))
}
//---------------------------------------------------------------------------
void         __fastcall CAlexMaker::Init          ( )
{
    if( !g_EtatInitialise)
    {
        EtatInitialize(gVersionDeDemonstration, gGestionEnvoiGED);
        g_EtatInitialise = true;
    }
    if( !m_Visu)
    {
        m_Visu    = NewTFrmVisualise( m_Owner, m_SessionName);

        m_Visu->OnSQLParams       = OnSQLParamsInterne;
        m_Visu->OnBDInitialized   = OnBDInitializedInterne;
        m_Visu->OnDebutDoc        = OnDebutDocInterne;
        m_Visu->OnDebutEtat       = OnDebutEtatInterne;
        m_Visu->OnFirstBandeEtat  = OnFirstBandeEtatInterne;
        m_Visu->OnBande           = OnBandeInterne;
        m_Visu->OnAfterFirstBandeInit = OnAfterFirstBandeInitInterne;
        m_Visu->OnChamp           = OnChampInterne;
        m_Visu->OnTableau         = OnTableauInterne;
        m_Visu->OnFinEtat         = OnFinEtatInterne;
        m_Visu->OnFinDoc          = OnFinDocInterne;
        m_Visu->fParamVisu        = OnParamVisu;
        m_Visu->OnError           = OnErreur;
        m_Visu->OnVariable        = OnVariable;

        m_Visu->edLangue->Position = m_Langue;
    }
}
void         __fastcall CAlexMaker::DeInit( )
{
    if( m_Visu){ DeleteTFrmVisualise( m_Visu);  m_Visu = NULL;}
}

bool __fastcall CAlexMaker::Show ( TYPE_IMPRESSION TypeImpr, enum TPrintRange PrintRange, int nPageDebut, int nPageFin)
{
    bool bRetour = false;
    try{
        AnsiString FileName, PathName, PathExe = ExtractFilePath(Application->ExeName);
        TList *m_DocList = NULL;
        int nNbEtat = 0;
        m_TypeImpr = TypeImpr;
        if( !m_TypeImpr && !m_ShowNbCopies && !m_NbCopies) return (false);
        Init();
        m_Visu->ShowNbCopies  = (m_TypeImpr!=ti_Imprimante)?true:m_ShowNbCopies;
        m_Visu->PDFInactif = m_PDFInactif;
        if( m_DocNameList->Count)
        {
            m_DocList = new TList();
            for( int i = 0; i < m_DocNameList->Count; i++)
            {
                FileName = m_DocNameList->Strings[ i];
                if( !FileExists( FileName))
                {
                    PathName = ExtractFilePath(FileName);
                    if( PathName.IsEmpty() || PathExe != PathName)
                    {
                        FileName = PathExe + ExtractFileName( FileName);
                    }
                }
                if( !FileExists( FileName))
                {
                    MessageBox( 0, AnsiString("Erreur Visualisation\nFichier non trouvé :\"" + m_DocNameList->Strings[ i] + "\"").c_str(), "Visualisateur", MB_ICONERROR);
                    continue;
                }
                TDocument *doc = NewTDocument( FileName);
                doc->Numero = i;
                TCoorRect r = doc->Marges;
                if( m_MargeGaucheMm != USHRT_MAX) r.Left.Mm   = m_MargeGaucheMm;
                if( m_MargeHautMm   != USHRT_MAX) r.Top.Mm    = m_MargeHautMm;
                if( m_MargeDroitMm  != USHRT_MAX) r.Right.Mm  = m_MargeDroitMm;
                if( m_MargeBasMm    != USHRT_MAX) r.Bottom.Mm = m_MargeBasMm;
                doc->Marges = r;
                TCoordonnee c;
                if( m_MargeHorsEnteteMm != USHRT_MAX) { c.Mm = m_MargeHorsEnteteMm; doc->MargeHorsEntete = c;}
                if( m_MargeHorsPiedMm   != USHRT_MAX) { c.Mm = m_MargeHorsPiedMm;   doc->MargeHorsPied = c;}
                m_DocList->Add( doc);
    //            m_DocList->Objects[ i] = doc;
                m_Visu->Ajoute( doc);
                nNbEtat++;
            }
        }
        m_Langue = max(m_Visu->edLangue->Min, min( m_Visu->edLangue->Max, m_Langue));
        m_Visu->edLangue->Position = m_Langue;
        if( m_Visu->CbDocument->Items->Count)
        {
            switch( TypeImpr)
            {
            case ti_Visu:
                if( !m_VisuName.IsEmpty())
                    m_Visu->Caption = m_VisuName;
                m_Visu->ShowModal();
            break;
            case ti_Imprimante:
                m_Visu->bPrintOnly    = !m_bPrepareLaVisu;
                m_Visu->PrintDialog1->PrintRange = PrintRange;
                m_Visu->PrintDialog1->FromPage = nPageDebut;
                m_Visu->PrintDialog1->ToPage = nPageFin;
                m_Visu->ActImprimerExecute( (TObject*)m_WantChoixImprimante);
            break;
            case ti_PDF:
                m_Visu->bPrintOnly    = !m_bPrepareLaVisu;
                m_Visu->ActPdfExecute( NULL);
            break;
            case ti_GED:
                m_Visu->bPrintOnly    = !m_bPrepareLaVisu;
                ASSERT( m_Visu->ActGED);
                m_Visu->ActImprimerExecute( m_Visu->ActGED);
            break;
            }
            bRetour = !m_Visu->Annulee;
        }else{
            ShowMessage( (TypeImpr==ti_Visu)?"Aucun état n'est à visualiser.": "Aucun état n'est à imprimer.");
        }
        if( m_DocNameList->Count)
        {
            m_Visu->FreeAllPages();
            for( int i = 0; i < m_DocList->Count; i++)
            {
                m_Visu->Deconnecte( (TDocument*)m_DocList->Items[ i]);
                DeleteTDocument( (TDocument*)m_DocList->Items[ i]);
            }
            delete m_DocList; m_DocList = NULL;
        }
    }CATCH_EXCEPTION( TAG( 3))
    return (bRetour);
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::Print( enum TPrintRange PrintRange, int nPageDebut, int nPageFin)
{
    if( gImpressionGroupeeGED) return PrintGED();
    return ( Show ( ti_Imprimante, PrintRange, nPageDebut, nPageFin) );
}
bool __fastcall CAlexMaker::PrintPdf( const AnsiString &File)
{
    Init();
    m_Visu->SaveDialog1->FileName = File;
    return ( Show ( ti_PDF, prAllPages, 0, 0) );
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::Preview( )
{
    return ( Show ( ti_Visu, (enum TPrintRange)0,0,0) );
}

//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::PrintGED( )
{
    return ( Show ( ti_GED, (enum TPrintRange)0,0,0) );
}
void __fastcall CAlexMaker::OnParamVisu( int &NbCopies)
{
    NbCopies = m_NbCopies;
}
//---------------------------------------------------------------------------
void __fastcall CAlexMaker::ClearEtats( )
{
    DeInit();
}
void         __fastcall CAlexMaker::SetLangue( int i)
{
    Init();
    m_Langue = max(m_Visu->edLangue->Min, min( m_Visu->edLangue->Max, i));
    m_Visu->edLangue->Position = m_Langue;
}

void __fastcall CAlexMaker::AjouteEtat( const AnsiString &DocFile, const AnsiString &EtatName, unsigned long Tag, CAlexMaker *pAM)
{
    Init();
    int index = DocumentsCharges->IndexOf( DocFile);
    TDocument *doc;
    if( index == -1)
    {
        doc = NewTDocument( DocFile, EtatName);
        if(doc->FileVersion < FILE_VERSION(2,2))
            DocumentsCharges->AddObject( DocFile, doc);

    }else
        doc = (TDocument*)DocumentsCharges->Objects[index];


    TCoorRect r = doc->Marges;
    if( m_MargeGaucheMm != USHRT_MAX) r.Left.Mm   = m_MargeGaucheMm;
    if( m_MargeHautMm   != USHRT_MAX) r.Top.Mm    = m_MargeHautMm;
    if( m_MargeDroitMm  != USHRT_MAX) r.Right.Mm  = m_MargeDroitMm;
    if( m_MargeBasMm    != USHRT_MAX) r.Bottom.Mm = m_MargeBasMm;
    doc->Marges = r;
    TEtat *e = doc->GetEtat( EtatName);
    if (e == NULL)
      throw EUser(TAGL,"Impossible de trouver l'état '" + EtatName + "' dans le fichier '" + DocFile + "'");
    if( pAM && (pAM != this))
    {
        e->TakeEvForces          = true;
        e->OnDebutEtatForce      = pAM->OnDebutEtatInterne;
        e->OnFinEtatForce        = pAM->OnFinEtatInterne;
        e->OnFirstBandeEtatForce = pAM->OnFirstBandeEtatInterne;
        e->OnBandeForce          = pAM->OnBandeInterne;
        e->OnAfterFirstBandeInitForce = pAM->OnAfterFirstBandeInitInterne;
        e->OnChampForce          = pAM->OnChampInterne;
        e->OnTableauForce        = pAM->OnTableauInterne;
        e->OnSQLParamsForce      = pAM->OnSQLParamsInterne;
        e->OnBDInitializedForce  = pAM->OnBDInitializedInterne;
        e->OnErrorForce          = pAM->OnErrorInterne;
        e->OnVariableForce       = pAM->OnVariableInterne;
        pAM->m_NbCopies          = m_NbCopies;
    }
    m_Visu->Ajoute( e, false, Tag);
    if(doc->FileVersion >= FILE_VERSION(2,2))
        DeleteTDocument( doc);
}

int __fastcall CAlexMaker::AjouteEtatNbPages( const AnsiString &DocFile, const AnsiString &EtatName, unsigned long Tag, CAlexMaker *pAM)
{
    Init();
    int index = DocumentsCharges->IndexOf( DocFile);
    TDocument *doc;
    if( index == -1)
    {
        doc = NewTDocument( DocFile, EtatName);
        if(doc->FileVersion < FILE_VERSION(2,2))
            DocumentsCharges->AddObject( DocFile, doc);

    }else
        doc = (TDocument*)DocumentsCharges->Objects[index];

    TCoorRect r = doc->Marges;
    if( m_MargeGaucheMm != USHRT_MAX) r.Left.Mm   = m_MargeGaucheMm;
    if( m_MargeHautMm   != USHRT_MAX) r.Top.Mm    = m_MargeHautMm;
    if( m_MargeDroitMm  != USHRT_MAX) r.Right.Mm  = m_MargeDroitMm;
    if( m_MargeBasMm    != USHRT_MAX) r.Bottom.Mm = m_MargeBasMm;
    doc->Marges = r;
    TEtat *e = doc->GetEtat( EtatName);
    if (e == NULL)
      throw EUser(TAGL,"Impossible de trouver l'état '" + EtatName + "' dans le fichier '" + DocFile + "'");
    if( pAM && (pAM != this))
    {
        e->TakeEvForces          = true;
        e->OnDebutEtatForce      = pAM->OnDebutEtatInterne;
        e->OnFinEtatForce        = pAM->OnFinEtatInterne;
        e->OnFirstBandeEtatForce = pAM->OnFirstBandeEtatInterne;
        e->OnBandeForce          = pAM->OnBandeInterne;
        e->OnAfterFirstBandeInitForce = pAM->OnAfterFirstBandeInitInterne;
        e->OnChampForce          = pAM->OnChampInterne;
        e->OnTableauForce        = pAM->OnTableauInterne;
        e->OnSQLParamsForce      = pAM->OnSQLParamsInterne;
        e->OnBDInitializedForce  = pAM->OnBDInitializedInterne;
        e->OnErrorForce          = pAM->OnErrorInterne;
        e->OnVariableForce       = pAM->OnVariableInterne;
        pAM->m_NbCopies          = m_NbCopies;
    }
    e = m_Visu->Ajoute( e, false, Tag);
    e->Initialize();
    if(doc->FileVersion >= FILE_VERSION(2,2))
        DeleteTDocument( doc);
    return e->NumberOfPage;
}

void  __fastcall CAlexMaker::AjouteEtatOLE( const AnsiString &OLEFile, bool Resize, bool ImprimeEnteteEtPied, unsigned long Tag, CAlexMaker *pAM)
{
    Init();
    TDocument *doc = NewTDocument( EmptyStr);
    TEtat *e = NewTEtatOLE( doc, OLEFile, Resize, ImprimeEnteteEtPied);
    e->Tag = Tag;
    if( e->Ole)
        m_Visu->Ajoute( e, false, Tag);
    else
        OnFinEtatInterne( e);
    DeleteTEtat( e);
    DeleteTDocument( doc);
}
//---------------------------------------------------------------------------
void __fastcall CAlexMaker::SetDocNameList(TStrings *pValue)
{
    try{
        m_DocNameList->Assign( pValue);
    }CATCH_EXCEPTION( TAG( 4))
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::OnDebutDocInterne(  TDocument  *Doc)
{
    bool bReturn = true;
    try{
        if( f_OnStartDoc)
        {
            TDocUser *d = new TDocUser( Doc);
            bReturn = f_OnStartDoc( d);
            delete d;
        }
    }CATCH_EXCEPTION( TAG( 5))
    return bReturn;
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::OnDebutEtatInterne( TEtat      *Etat)
{
    bool bReturn = true;
    try{
        if( m_NbCopies)  Etat->NbCopies = m_NbCopies;
        if( f_OnStartEtat)
        {
            TEtatUser *e = new TEtatUser( Etat);
            bReturn = f_OnStartEtat( e);
            delete e;
        }
     //   bReturn &= ( (m_TypeImpr != ti_Imprimante) /*|| Etat->NbCopies*/);
    }CATCH_EXCEPTION( TAG( 6))
    return bReturn;
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::OnSQLParamsInterne( TEtat      *Etat, TParams *SQLParam)
{
    bool bReturn = true;
    try{
        if( f_OnSQLParams)
        {
            TEtatUser *e = new TEtatUser( Etat);
            bReturn = f_OnSQLParams( e, SQLParam);
            delete e;
        }
    }CATCH_EXCEPTION( TAG( 7))
    return bReturn;
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::OnBDInitializedInterne( TEtat *Etat)
{
    bool bReturn = true;
    try{
        if( f_OnBDInitialized)
        {
            TEtatUser *e = new TEtatUser( Etat);
            bReturn = f_OnBDInitialized( e, Etat->BaseDeDonnee);
            delete e;
        }
    }CATCH_EXCEPTION( TAGL)
    return bReturn;
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::OnFirstBandeEtatInterne(     TBande     *Bande)
{
    bool bReturn = true;
    try{
      TBandeUser *b = new TBandeUser( Bande);
      if( f_OnFirstBandeEtat)    bReturn = f_OnFirstBandeEtat( b);
      delete b;
    }CATCH_EXCEPTION( TAGL)
    return bReturn;
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::OnBandeInterne(     TBande     *Bande)
{
    bool bReturn = true;
    try{
        bool bFirstPage = (Bande->EtatOwner->CurrentPage == 1);
        TBandeUser *b = new TBandeUser( Bande);
        switch( Bande->Type)
        {
            case e_EnTete :
                    if( bFirstPage)
                    {
                        if( f_OnFirstPageHeader)        bReturn = f_OnFirstPageHeader( b);
                    }else if( f_OnPageHeader)           bReturn = f_OnPageHeader( b);
                break;
            case e_Debut :
                    if( Bande->Niveau <= 1)
                    {
                        if( f_OnBandeDebut)             bReturn = f_OnBandeDebut( b);
                    }else if( f_OnBandeDebutSection)    bReturn = f_OnBandeDebutSection( b);
                break;
            case e_DebutColonne :
                    if( f_OnBandeDebutColonne)          bReturn = f_OnBandeDebutColonne( b);
                break;
            case e_ReportDebDePage :
                    if( f_OnBandeReportDebutDePage)     bReturn = f_OnBandeReportDebutDePage( b);
                break;
            case e_Principal :
                    if( f_OnBandeDetail)                bReturn = f_OnBandeDetail( b);
                break;
            case e_ReportFinDePage :
                    if( f_OnBandeReportFinDePage)       bReturn = f_OnBandeReportFinDePage( b);
                break;
            case e_FinColonne :
                    if( f_OnBandeFinColonne)            bReturn = f_OnBandeFinColonne( b);
                break;
            case e_Fin :
                    if( Bande->Niveau <= 1)
                    {
                        if( f_OnBandeFin)               bReturn = f_OnBandeFin( b);
                    }else if( f_OnBandeFinSection)      bReturn = f_OnBandeFinSection( b);
                break;
            case e_Pied :
                    if( bFirstPage)
                    {
                        if( f_OnFirstPageFooter)        bReturn = f_OnFirstPageFooter( b);
                    }else if( f_OnPageFooter)           bReturn = f_OnPageFooter( b);
                break;
            case e_SautDePage        :
                    if( f_OnSautDePage)                 bReturn = f_OnSautDePage( b);
                break;
            default :
                    if( (Bande->Type > e_Utilisateur) && f_OnBandeUtilisateur) bReturn = f_OnBandeUtilisateur( b);
                break;
        }
        delete b;
    }CATCH_EXCEPTION( TAG( 8))
    return bReturn;
}
void __fastcall CAlexMaker::OnAfterFirstBandeInitInterne( const TBande     *Bande)
{
    try{
        TBandeUser *b = new TBandeUser( Bande);
        if( f_OnAfterFirstBandeInit) f_OnAfterFirstBandeInit( b);
        delete b;
    }CATCH_EXCEPTION( TAG( 9))
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::OnChampInterne(     TCpChamp   *Champ)
{
    bool bReturn = true;
    try{
        if( f_OnChamp)
        {
            TCpChampUser *c = new TCpChampUser( Champ);
            bReturn = f_OnChamp( c);
            delete c;
        }
    }CATCH_EXCEPTION( TAG( 10))
    return bReturn;
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::OnTableauInterne(     TCpTableau   *Tableau)
{
    bool bReturn = true;
    try{
        if( f_OnTableau)
        {
            TCpTableauUser *c = new TCpTableauUser( Tableau);
            bReturn = f_OnTableau( c);
            delete c;
        }
    }CATCH_EXCEPTION( TAG( 11))
    return bReturn;
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::OnFinEtatInterne(   TEtat      *Etat)
{
    bool bReturn = true;
    try{
        if( f_OnEndEtat)
        {
            TEtatUser *e = new TEtatUser( Etat);
            bReturn = f_OnEndEtat( e);
            delete e;
        }
    }CATCH_EXCEPTION( TAG( 12))
    return bReturn;
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::OnFinDocInterne(    TDocument  *Doc)
{
    bool bReturn = true;
    try{
        if( f_OnEndDoc)
        {
            TDocUser *d = new TDocUser( Doc);
            bReturn = f_OnEndDoc( d);
            delete d;
        }
    }CATCH_EXCEPTION( TAG( 13))
    return bReturn;
}
//---------------------------------------------------------------------------
bool __fastcall CAlexMaker::GetImpressionFaite()
{
    bool bReturn = false;
    try{
        bReturn = m_Visu->ImpressionFaite;
    }CATCH_EXCEPTION( TAG( 14))
    return bReturn;
}
void __fastcall CAlexMaker::OnErrorInterne(const TObject* o, const AnsiString &Message)
{
    try{
        if( f_OnErreur)
        {
            if( ((TObject*)o)->ClassNameIs("TCpChamp"))
            {
                TCpChampUser *c = new TCpChampUser( (const TCpChamp *)o);
                f_OnErreur( c, Message);
                delete c;
            }else if( ((TObject*)o)->ClassNameIs("TBande"))
            {
                TBandeUser *b = new TBandeUser( (const TBande*)o);
                f_OnErreur( b, Message);
                delete b;
            }else{
                TEtatUser *e = new TEtatUser( (const TEtat *)o);
                f_OnErreur( e, Message);
                delete e;
            }
        }
    }CATCH_EXCEPTION( TAG( 13))
}
bool __fastcall CAlexMaker::OnVariableInterne(const TObject* o, const AnsiString &Variable, TFieldType &Type, AnsiString &Valeur)
{
    bool bReturn = true;
    try{
        if( f_OnVariable)
        {
            if( ((TObject*)o)->ClassNameIs("TCpChamp"))
            {
                TCpChampUser *c = new TCpChampUser( (const TCpChamp *)o);
                f_OnVariable( c, Variable, Type, Valeur);
                delete c;
            }else if( ((TObject*)o)->ClassNameIs("TBande"))
            {
                TBandeUser *b = new TBandeUser( (const TBande*)o);
                f_OnVariable( b, Variable, Type, Valeur);
                delete b;
            }else{
                TEtatUser *e = new TEtatUser( (const TEtat *)o);
                f_OnVariable( e, Variable, Type, Valeur);
                delete e;
            }
         /*   const TObject *o;
            const TCpChamp *CpChampEnCours = dynamic_cast<const TCpChamp *>(o);
            const TBande   *BandeEnCours   = dynamic_cast<const TBande *>(o);
            if( CpChampEnCours)
            {
                TCpChampUser *c = new TCpChampUser( CpChampEnCours);
                f_OnVariable( c, Variable, Type, Valeur);
                delete c;
            }else if( CpChampEnCours)
            {
                TBandeUser *b = new TBandeUser( BandeEnCours);
                f_OnVariable( b, Variable, Type, Valeur);
                delete b;
            }else{
                TEtatUser *e = new TEtatUser( dynamic_cast<const TEtat *>(o));
                f_OnVariable( e, Variable, Type, Valeur);
                delete e;
            }  */
        }
    }CATCH_EXCEPTION( TAG( 13))
    return bReturn;
}


//---------------------------------------------------------------------------
//----------------------------   TDocUser   ---------------------------------
//---------------------------------------------------------------------------
TFont* __fastcall  TDocUser::GetFontDefaut( )const
{
    try{
        return m_Doc? m_Doc->FontDefaut : NULL;
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC))
    return NULL;
}
//---------------------------------------------------------------------------
TColor __fastcall  TDocUser::GetColorDefaut( )const
{
    try{
        return m_Doc? m_Doc->ColorDefaut : 0;
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+1))
    return (TColor)0;
}
//---------------------------------------------------------------------------
EICCurrencyFmt* __fastcall  TDocUser::GetFormatCurDefaut( )const
{
    try{
        return m_Doc? m_Doc->FormatCurDefaut : 0;
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+2))
    return 0;
}
//---------------------------------------------------------------------------
EICNumberFmt* __fastcall  TDocUser::GetFormatNumDefaut( )const
{
    try{
        return m_Doc? m_Doc->FormatNumDefaut : 0;
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+3))
    return 0;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TDocUser::GetTitre()const
{
    try{
        return m_Doc? m_Doc->Titre : EmptyStr;
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+4))
    return EmptyStr;
}
//---------------------------------------------------------------------------
void __fastcall TDocUser::SetTitre( const AnsiString& t)
{
    try{
        if ( m_Doc) m_Doc->Titre = t;
        else ASSERT( false);
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+5))
}
//---------------------------------------------------------------------------
int __fastcall  TDocUser::GetNumero()const
{
    try{
        return m_Doc? m_Doc->Numero : -1;
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+6))
    return -1;
}
//---------------------------------------------------------------------------
void __fastcall  TDocUser::SetFontDefaut( TFont* f)
{
    try{
        if( m_Doc) m_Doc->FontDefaut->Assign( f);
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+7))
}
//---------------------------------------------------------------------------
void __fastcall  TDocUser::SetColorDefaut( TColor c)
{
    try{
        if( m_Doc) m_Doc->ColorDefaut = c;
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+8))
}
//---------------------------------------------------------------------------
void __fastcall  TDocUser::SetFormatCurDefaut( EICCurrencyFmt* c)
{
    try{
        if( m_Doc) m_Doc->FormatCurDefaut->Assign( *c);
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+9))
}
//---------------------------------------------------------------------------
void __fastcall  TDocUser::SetFormatNumDefaut( EICNumberFmt* n)
{
    try{
        if( m_Doc) m_Doc->FormatNumDefaut->Assign( *n);
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+10))
}
//---------------------------------------------------------------------------
void __fastcall TDocUser::GetLstStylesDoc( EICListStyle **pLstStyles)
{
  try
  {
    if( m_Doc && m_Doc->Styles)
    {
      if( !(*pLstStyles)) (*pLstStyles) = NewEICListStyle();
      (*pLstStyles)->Assign( m_Doc->Styles);
    }
  }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+12))
}
void __fastcall TDocUser::SetLstStylesDoc( EICListStyle *pLstStyles)
{
  try
  {
    if( pLstStyles && (m_Doc && m_Doc->Styles))
      m_Doc->Styles->Assign( pLstStyles);
  }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+13))
}
bool __fastcall  TDocUser::GetInverserMargesSurPagePaire()const
{
    try{
        return m_Doc? HIWORD( m_Doc->TypePapier) >> 16 : -1;
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+6))
    return -1;
}
void __fastcall  TDocUser::SetInverserMargesSurPagePaire( bool b)
{
    try{
        if( m_Doc) m_Doc->TypePapier = MAKELONG( LOWORD( m_Doc->TypePapier), b );
    }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+6))
}

int __fastcall  TDocUser::GetHauteur( )
{
 try {
     if(m_Doc)
        return m_Doc->Hauteur.DixMm;
 }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+18))
 return -1;
}

void __fastcall  TDocUser::SetHauteur(int iHauteur)
{
 try {
     if(m_Doc)
        m_Doc->Hauteur.DixMm = iHauteur;
 }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+17))
}

int __fastcall  TDocUser::GetLargeur( )
{
 try {
     if(m_Doc)
        return m_Doc->Largeur.DixMm;
     else
        return -1;
 }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+18))
 return -1;
}

void __fastcall  TDocUser::SetLargeur(int iLargeur)
{
 try {
     if(m_Doc)
        m_Doc->Largeur.DixMm = iLargeur;
 }CATCH_EXCEPTION( TAG( DEB_TAG_DOC+19))
}

//---------------------------------------------------------------------------
//----------------------------   TEtatUser   --------------------------------
//---------------------------------------------------------------------------
__fastcall TEtatUser::TEtatUser( TEtat* Etat):TObject()
{
    try{
        m_Etat = Etat;
        m_ConstEtat = Etat;
        m_Bd = NULL;
        m_DocProprietaire = new TDocUser( Etat->DocOwner);
        m_Lst = new TStringList( );
        m_Lst->Clear();
        if( m_Etat)
        {
            TBande *b = NULL;
            for( b = m_Etat->SearchBande( e_Principal);
                 b && b->LstBandes != NULL;
                 b = b->LstBandes->SearchBande( e_Principal))
            {
                if( b->LstBandes->bRuptureVisible)
                    m_Lst->Add( b->ChpRupture);
            }
        }
        m_Lst->OnChange = OnChangeLstRupture;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT))
}
__fastcall TEtatUser::TEtatUser( const TEtat* Etat):TObject()
{
    try{
        m_ConstEtat = Etat;
        m_DocProprietaire = new TDocUser( Etat->DocOwner);
        m_Lst = new TStringList( );
        m_Lst->Clear();
        if( m_ConstEtat)
        {
            TBande *b = NULL;
            for( b = m_ConstEtat->SearchBande( e_Principal);
                 b && b->LstBandes != NULL;
                 b = b->LstBandes->SearchBande( e_Principal))
            {
                if( b->LstBandes->bRuptureVisible)
                    m_Lst->Add( b->ChpRupture);
            }
        }
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT))
}
__fastcall TEtatUser::~TEtatUser( )
{
    try{
        delete m_DocProprietaire;
        delete m_Lst;
        if( m_Bd) delete m_Bd;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+1))
}
//---------------------------------------------------------------------------
int        __fastcall TEtatUser::GetLargeur( )
{
    try{
        return m_ConstEtat->Largeur.DixMm;
    }catch(...)
    { return 0;}
}
AnsiString  __fastcall TEtatUser::GetChampDB( const AnsiString &ChampDB)const
{
    try{
        return m_ConstEtat->GetChampDB(ChampDB);
    }catch(...)
    { return "ERREUR";}
}
TDataSet*    __fastcall TEtatUser::GetBaseDeDonnee( ) const
{
    try{
        return m_ConstEtat->BaseDeDonnee;
    }catch(...)
    { return NULL;}
}
//---------------------------------------------------------------------------
short      __fastcall TEtatUser::GetNumero()const
{
    try{
        if( m_ConstEtat)
        {
            return (m_ConstEtat->NumeroInOriginalFileName != -1)?
                        m_ConstEtat->NumeroInOriginalFileName
                    :   m_ConstEtat->DocOwner->IndexOf( m_ConstEtat);
        }
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+2))
    return -1;
}
//---------------------------------------------------------------------------
long       __fastcall TEtatUser::GetNbEnreg()const
{
    try{
        return m_ConstEtat->BaseDeDonnee->RecordCount;
    }catch(...)
    { return 0;}
}
//---------------------------------------------------------------------------
void __fastcall TEtatUser::OnChangeLstRupture(System::TObject* Sender)
{
    try{
        SetRuptures( m_Lst);
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+3))
}
void       __fastcall TEtatUser::SetRuptures( TStringList *Lst)
{
    try{
        if( m_Etat)
        {
            TBande *b = NULL;
            int i;
            for( i = 0, b = m_Etat->SearchBande( e_Principal);
                 b && b->LstBandes != NULL;
                 b = b->LstBandes->SearchBande( e_Principal), i++)
            {
                if( i < Lst->Count)
                {
                    b->ChpRupture = Lst->Strings[i];
                    b->LstBandes->bRuptureVisible = Lst->Objects[i]==NULL;
                }else b->LstBandes->bRuptureVisible = false;
            }
        }
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+4))
}
//---------------------------------------------------------------------------
AnsiString __fastcall TEtatUser::GetSQL()const
{
    try{
        return m_ConstEtat? m_ConstEtat->Requete : EmptyStr;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+5))
    return EmptyStr;
}
void __fastcall TEtatUser::SetSQL( const AnsiString& SQL)
{
    try{
        if( m_Etat) m_Etat->Requete = SQL;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+6))
}
//---------------------------------------------------------------------------
AnsiString __fastcall TEtatUser::GetTitre()const
{
    try{
        return m_ConstEtat? m_ConstEtat->Titre : EmptyStr;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+7))
    return EmptyStr;
}
//---------------------------------------------------------------------------
void __fastcall TEtatUser::SetTitre( const AnsiString& t)
{
    try{
        if ( m_Etat) m_Etat->Titre = t;
        else ASSERT( false);
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+8))
}
//---------------------------------------------------------------------------
short      __fastcall TEtatUser::GetNbCopies()const
{
    try{
        return m_ConstEtat? m_ConstEtat->NbCopies : 0;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+9))
    return 0;
}
void __fastcall TEtatUser::SetNbCopies( short n)
{
    try{
        if( m_Etat) m_Etat->NbCopies = n;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+10))
}
//---------------------------------------------------------------------------
bool __fastcall TEtatUser::GetPortrait( )const
{
    try{
        return m_ConstEtat->Portrait;
    }catch(...)
    { return false;}
}
void       __fastcall TEtatUser::SetPortrait( bool b)
{
    try{
        if( m_Etat) m_Etat->Portrait = b;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+11))
}
//---------------------------------------------------------------------------
int __fastcall TEtatUser::GetTag( )const
{
    try{
        return m_ConstEtat->Tag;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+12))
    return 0;
}
void       __fastcall TEtatUser::SetTag( int i)
{
    try{
        if( m_Etat) m_Etat->Tag = i;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+13))
}

//---------------------------------------------------------------------------
int __fastcall TEtatUser::GetNombreDePages()const
{
    try{
        return m_ConstEtat? m_ConstEtat->NumberOfPage : -1;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+14))
    return -1;
}
void __fastcall TEtatUser::SetNombreDePages( int n)
{
    try{
        if( m_Etat) m_Etat->NumberOfPage = n;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+15))
}
//---------------------------------------------------------------------------
int __fastcall TEtatUser::GetPageCourante()const
{
    try{
        return m_ConstEtat? m_ConstEtat->CurrentPage : -1;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+16))
    return -1;
}
void __fastcall TEtatUser::SetPageCourante( int n)
{
    try{
        if( m_Etat) m_Etat->CurrentPage = n;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+17))
}
//---------------------------------------------------------------------------
enum type_debutpage __fastcall TEtatUser::GetDebutPage( )const
{
    try{
        return m_ConstEtat->DebPage;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+18))
    return Deb_AutreDocument;
}
void       __fastcall TEtatUser::SetDebutPage( enum type_debutpage i)
{
    try{
        if( m_Etat) m_Etat->DebPage = i;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+19))
}
bool       __fastcall TEtatUser::GetCalculNbPages( )const
{
    try{
        return !m_ConstEtat->DocOwner->IsValidSupport();
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+18))
    return false;
}
bool       __fastcall TEtatUser::GetReinitBDDApresCalculsPage()const
{
    try{
        return m_ConstEtat->ReinitBDDApresCalculsPage;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+18))
    return false;
}
void       __fastcall TEtatUser::SetReinitBDDApresCalculsPage(bool b)
{
    try{
        if( m_Etat) m_Etat->ReinitBDDApresCalculsPage = b;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+19))
}
EICCurrencyFmt* __fastcall  TEtatUser::GetFormatCurDefaut( )const
{
    try{
        return m_ConstEtat? m_ConstEtat->FormatCurDefaut : 0;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+20))
    return 0;
}
void __fastcall  TEtatUser::SetFormatCurDefaut( EICCurrencyFmt* c)
{
    try{
        if( m_Etat) m_Etat->FormatCurDefaut = c;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+21))
}
int __fastcall  TEtatUser::GetEspaceApres( )const
{
    try{
        return m_ConstEtat? m_ConstEtat->EspaceApres.DixMm : 0;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+20))
    return 0;
}
void __fastcall  TEtatUser::SetEspaceApres( int c)
{
    try{
        if( m_Etat) m_Etat->EspaceApres.DixMm = c;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+21))
}
bool       __fastcall TEtatUser::GetForcerMonetaireSaufZeroSignificatif()const
{
    try{
        return m_ConstEtat->ForcerMonetaireSaufZeroSignificatif;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+22))
    return false;
}
void       __fastcall TEtatUser::SetForcerMonetaireSaufZeroSignificatif(bool b)
{
    try{
        if( m_Etat) m_Etat->ForcerMonetaireSaufZeroSignificatif = b;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+23))
}
int __fastcall  TEtatUser::GetHauteurCpOLE()const
{
    try{
        if( m_ConstEtat->Ole) return (m_ConstEtat->Ole->Hauteur + m_ConstEtat->DocOwner->MargeVertCp*2 ).DixMm;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+22))
    return 0;
}
int __fastcall  TEtatUser::GetInclusDansUnEtat()const
{
    try{
        if( m_ConstEtat->EtatAppelant && (m_ConstEtat->EtatAppelant->EtatSuivant != m_ConstEtat))
            return (m_ConstEtat->EtatAppelant->NumeroInOriginalFileName != -1)?
                        m_ConstEtat->EtatAppelant->NumeroInOriginalFileName
                    :   m_ConstEtat->EtatAppelant->DocOwner->IndexOf( m_ConstEtat->EtatAppelant);
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+22))
    return -1;
}
AnsiString __fastcall  TEtatUser::GetFiligrane( )const
{
    try{
        if( m_ConstEtat) return m_ConstEtat->Filigrane;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+23))
    return EmptyStr;
}
void __fastcall  TEtatUser::SetFiligrane( const AnsiString &s)
{
    try{
        if( m_Etat) m_Etat->Filigrane = s;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+24))
}
AnsiString __fastcall TEtatUser::GetBD_User()const
{
    try{
        if( m_ConstEtat) return m_ConstEtat->User;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+25))
    return EmptyStr;
}
void __fastcall TEtatUser::SetBD_User(const AnsiString &s)
{
    try{
        if( m_Etat) m_Etat->User = s;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+26))
}
AnsiString __fastcall TEtatUser::GetBD_Password()const
{
    try{
        if( m_ConstEtat) return m_ConstEtat->Password;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+27))
    return EmptyStr;
}
void __fastcall TEtatUser::SetBD_Password(const AnsiString &s)
{
    try{
        if( m_Etat) m_Etat->Password = s;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+28))
}
#ifdef _MYSQL
TZZMySqlQuery* __fastcall TEtatUser::GetMySqlQuery()const
{
    try{
        if( m_ConstEtat) return m_ConstEtat->MySqlQuery;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+27))
}

void __fastcall TEtatUser::SetMySqlQuery(TZZMySqlQuery *Query)
{
    try{
        if( m_Etat) m_Etat->MySqlQuery = Query;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+28))
}
#endif
AnsiString __fastcall TEtatUser::GetDatabaseName()const
{
    try{
        if( m_ConstEtat) return m_ConstEtat->DatabaseName;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+23))
    return EmptyStr;
}
void __fastcall TEtatUser::SetDatabaseName(const AnsiString &s)
{
    try{
        if( m_Etat) m_Etat->DatabaseName = s;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+24))
}
AnsiString __fastcall TEtatUser::GetImageFond()const
{
    try{
        if( m_ConstEtat) return m_ConstEtat->DocPdf;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+25))
    return EmptyStr;
}
void __fastcall TEtatUser::SetImageFond(const AnsiString &s)
{
    try{
        if( m_Etat) m_Etat->DocPdf = s;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+26))
}
bool       __fastcall TEtatUser::GetReportRuptureHautPg()const
{
    try{
        return m_ConstEtat->ReportRupture;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+27))
    return false;
}
void       __fastcall TEtatUser::SetReportRuptureHautPg(bool b)
{
    try{
        if( m_Etat) m_Etat->ReportRupture = b;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+28))
}
AnsiString __fastcall TEtatUser::GetGED_Criteres()const
{
    try{
        if( m_ConstEtat) return m_ConstEtat->GED_Criteres;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+25))
    return EmptyStr;
}
void __fastcall TEtatUser::SetGED_Criteres(const AnsiString &s)
{
    try{
        if( m_Etat) m_Etat->GED_Criteres = s;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+26))
}
AnsiString      __fastcall TEtatUser::GetNomDocGED()const
{
    try{
        if( m_ConstEtat) return m_ConstEtat->NomDocGED;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+27))
    return EmptyStr;
}
void            __fastcall TEtatUser::SetNomDocGED(const AnsiString &s)
{
    try{
        if( m_Etat) m_Etat->NomDocGED = s;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+28))
}
TBandeUser* __fastcall TEtatUser::GetBande(TYPE_BANDE pType, WORD pNiveau)const
{
    try{
        if( m_ConstEtat)
        {
          if( m_Bd != NULL)
          {
            if( (m_Bd->TypeBande == pType) && (m_Bd->Niveau == pNiveau))
              return m_Bd;
            else
            {
              delete m_Bd;
              (TBandeUser*)m_Bd = NULL;
            }
          }
          TBande* bd = m_ConstEtat->GetBande( pType, pNiveau);
          if( bd) (TBandeUser*)m_Bd = new TBandeUser( bd);
        }
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+29))
    return m_Bd;
}

bool __fastcall TEtatUser::GetVersPDF()const
{
    try{
        if( m_ConstEtat) return m_ConstEtat->VersPDF;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+30))
    return false;
}

void __fastcall TEtatUser::SetVersPDF(const bool &b)
{
    try{
        if( m_Etat) m_Etat->VersPDF = b;
    }CATCH_EXCEPTION( TAG( DEB_TAG_ETAT+31))
}

//---------------------------------------------------------------------------
//---------------------------   TBandeUser   --------------------------------
//---------------------------------------------------------------------------
__fastcall TBandeUser::TBandeUser( TBande* bande):TObject()
{
    try{
        m_Bande = bande;
        m_BandeConst = bande;
        m_EtatProprietaire = new TEtatUser( bande->EtatOwner);
        Cp = NULL;
        CpTab = NULL;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE))
};
__fastcall TBandeUser::TBandeUser( const TBande* bande):TObject()
{
    try{
        m_Bande = NULL;
        m_BandeConst = bande;
        m_EtatProprietaire = new TEtatUser( bande->EtatOwner);
        Cp = NULL;
        CpTab = NULL;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE))
};
__fastcall TBandeUser::~TBandeUser( )
{
    try{
        delete m_EtatProprietaire;
        if( Cp)    delete Cp;
        if( CpTab) delete CpTab;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+1))
}
AnsiString __fastcall TBandeUser::GetTitre()const
{
    try{
        return m_BandeConst? m_BandeConst->Titre: EmptyStr;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+2))
    return EmptyStr;
}
AnsiString __fastcall TBandeUser::GetChampRupture()const
{
    try{
        return m_BandeConst && m_BandeConst->LstBandesOwner &&
               m_BandeConst->LstBandesOwner->BandeOwner? m_BandeConst->LstBandesOwner->BandeOwner->ChpRupture: EmptyStr;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+3))
    return EmptyStr;
}
AnsiString __fastcall TBandeUser::GetValeurChampRupture()const
{
    try{
        return m_BandeConst && m_BandeConst->LstBandesOwner &&
                m_BandeConst->LstBandesOwner->BandeOwner? m_BandeConst->LstBandesOwner->BandeOwner->ValeurChpRupture: EmptyStr;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+4))
    return EmptyStr;
}
bool       __fastcall TBandeUser::GetSautDePageAvant()const
{
    try{
        return m_BandeConst->SautDePageAvant;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+5))
    return false;
}
void       __fastcall TBandeUser::SetSautDePageAvant(bool b)
{
    try{
        m_Bande->SautDePageAvant = b;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+6))
}
bool       __fastcall TBandeUser::GetSautDePageApres()const
{
    try{
        return m_BandeConst->SautDePageApres;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+7))
    return false;
}
void       __fastcall TBandeUser::SetSautDePageApres(bool b)
{
    try{
        m_Bande->SautDePageApres = b;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+8))
}
int        __fastcall TBandeUser::GetNumBandeUtilPrecedente()const
{
    try{
        return m_BandeConst->NumBandeUtilPrecedente;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+9))
    return 0;
}
void       __fastcall TBandeUser::SetNumBandeUtilPrecedente(int i)
{
    try{
        m_Bande->NumBandeUtilPrecedente = i;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+10))
}
int        __fastcall TBandeUser::GetNumBandeUtilSuivante()const
{
    try{
        return m_BandeConst->NumBandeUtilSuivante;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+11))
    return 0;
}
void       __fastcall TBandeUser::SetNumBandeUtilSuivante(int i)
{
    try{
        m_Bande->NumBandeUtilSuivante = i;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+12))
}
bool       __fastcall TBandeUser::GetPremiereBandeDetail()const
{
    try{
        if(m_BandeConst->Type == e_Principal)
            return (!m_BandeConst->PreviousBande || (m_BandeConst->PreviousBande->Type != e_Principal));
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+13))
    return false;
}
bool       __fastcall TBandeUser::GetAutoLoop()const
{
   try{
       return m_BandeConst->bAutoLoop;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+14))
    return false;
}
void       __fastcall TBandeUser::SetAutoLoop(bool b)
{
    try{
        m_Bande->bAutoLoop = b;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+15))
}
AnsiString __fastcall TBandeUser::GetEtatAImprimerApres()const
{
    try{
        return m_BandeConst->EtatSuivant;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+16))
    return EmptyStr;
}
void       __fastcall TBandeUser::SetEtatAImprimerApres(const AnsiString &s)
{
    try{
        m_Bande->EtatSuivant = s;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+17))
}
int        __fastcall TBandeUser::GetIndiceRepetition()const
{
    try{
        if( m_BandeConst->Type == e_Principal)
            return m_BandeConst->IndiceRepetition;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+18))
    throw EUser( TAG( DEB_TAG_BANDE+18), "L'indice de répétition n'est utilisable que sur la bande détail.");
  #pragma warn -8066
    return 0;
  #pragma warn .8066
}


TCpChampUser*  __fastcall TBandeUser::GetChamp(const AnsiString &Nom)const
{
    try{
        if( Cp && (Cp->Nom == Nom)) return Cp;
        TCpChamp *c = m_BandeConst->GetCpChamp( Nom);
//        if( !c) throw EUser( TAG( 10), "Nom de champ ("+Nom+") inconnu");

        if( Cp) {delete Cp; (TCpChampUser*)Cp = NULL;}
        if( c)  (TCpChampUser*) Cp = new TCpChampUser( c);
        return Cp;
    }//catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+19))
    return NULL;
}
TCpTableauUser*  __fastcall TBandeUser::GetTableau(const AnsiString &Nom)const
{
    try{
        if( CpTab && (CpTab->Nom == Nom)) return CpTab;
        TCpTableau *c = m_BandeConst->GetCpTableau( Nom);
//        if( !c) throw new EUser( TAG( 11), "Nom de champ inconnu");

        if( CpTab) {delete CpTab; (TCpTableauUser*)CpTab = NULL;}
        if( c)     (TCpTableauUser*)CpTab = new TCpTableauUser( c);
        return CpTab;
    }//catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+20))
    return NULL;
}
int        __fastcall TBandeUser::GetHauteurDispoApres()const
{
    try{
        return (m_BandeConst->EtatOwner->Hauteur - m_BandeConst->Top - m_BandeConst->EtatOwner->CalculPlaceVoulueEnBas(m_BandeConst)).DixMm;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+21))
    return 0;
}
int        __fastcall TBandeUser::GetHauteurDispoApres2()const
{
    try{
        //TCoordonnee Bas = TCoordonnee::Pixels2Twips(m_BandeConst->Top.PixelsR[RESOLUTION_REF_ECRAN] + m_BandeConst->Hauteur.PixelsR[RESOLUTION_REF_ECRAN], RESOLUTION_REF_ECRAN);
        return (m_BandeConst->EtatOwner->Hauteur - m_BandeConst->Top - m_BandeConst->EtatOwner->HauteurPied/*déjà inclu ds la hauteur du pied - m_BandeConst->DocOwner->Marges.Bottom*/ ).DixMm;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+22))
    return 0;
}
TYPE_BANDE __fastcall TBandeUser::GetTypeBande()const
{
    try{
        if( m_BandeConst->Type > e_Utilisateur)
            return e_Utilisateur;
        return m_BandeConst->Type;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+23))
    return (TYPE_BANDE)0;
}
int        __fastcall TBandeUser::GetNumBandeUtil()const
{
    try{
        return m_BandeConst->Type - e_Utilisateur;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+24))
    return (TYPE_BANDE)0;
}
int        __fastcall TBandeUser::GetHaut()const
{
    try{
        return m_BandeConst->EtatOwner->BasDerniereBande.DixMm;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+25))
    return 0;
}
void       __fastcall TBandeUser::SetHaut(int h)
{
    try{
        m_Bande->EtatOwner->BasDerniereBande = TCoordonnee::DixMm2Twips(h);
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+26))
}
int        __fastcall TBandeUser::GetHauteur()const
{
    try{
        return m_BandeConst->Hauteur.DixMm;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+27))
    return 0;
}
void       __fastcall TBandeUser::SetHauteur(int h)
{
    try{
        m_Bande->HauteurForcee = TCoordonnee::DixMm2Twips(h);
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+28))
}
bool       __fastcall TBandeUser::GetPrisDansCalculColonne()const
{
    try{
        return  m_BandeConst->PrisDansCalculColonne;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+27))
    return 0;
}
void       __fastcall TBandeUser::SetPrisDansCalculColonne(bool b)
{
    try{
        m_Bande->PrisDansCalculColonne = b;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+28))
}
int        __fastcall TBandeUser::GetNumeroDeLaBandeDansLaPage()const
{
    try{
        return m_BandeConst->EtatOwner->NbBandesSurLaPage + 1;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+27))
    return 0;
}
WORD       __fastcall TBandeUser::GetNiveau()const
{
    try{
        return m_BandeConst->Niveau;
    }CATCH_EXCEPTION( TAG( DEB_TAG_BANDE+28))
    return 0;
}

//---------------------------------------------------------------------------
//---------------------------   TChampUser   --------------------------------
//---------------------------------------------------------------------------
__fastcall TCpChampUser::~TCpChampUser( )
{

    try{
        if( m_CpChamp)
        {
            ASSERT( m_Font->PixelsPerInch == m_CpChamp->Font->PixelsPerInch);
            EICFont *f = EICFont::CreateEICFont( m_Font);
            if( *(m_CpChamp->Font) != *f )
                m_CpChamp->Font = f;
            delete f;
        }
        delete m_Font;
        delete m_BandeProprietaire;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP))
}
__fastcall TCpChampUser::TCpChampUser( TCpChamp* CpChamp):TObject()
{
    try{
        m_CpChamp           = CpChamp;
        m_ConstCpChamp      = CpChamp;
        m_BandeProprietaire = new TBandeUser( CpChamp->BandeHt);
        m_Font = new TFont();
        m_Font->PixelsPerInch = CpChamp->Font->PixelsPerInch;

        m_Font->Assign( CpChamp->Font);
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+1))
}
__fastcall TCpChampUser::TCpChampUser( const TCpChamp* CpChamp):TObject()
{
    try{
        m_ConstCpChamp           = CpChamp;
        m_BandeProprietaire = new TBandeUser( CpChamp->BandeHt);
        m_Font = new TFont();
        m_Font->PixelsPerInch = CpChamp->Font->PixelsPerInch;
        m_Font->Assign( CpChamp->Font);
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+1))
}
AnsiString __fastcall TCpChampUser::GetNom()const
{
    try{
        return m_ConstCpChamp? m_ConstCpChamp->Nom: EmptyStr;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+2))
    return EmptyStr;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TCpChampUser::GetChampDB()const
{
    try{
        return m_ConstCpChamp? m_ConstCpChamp->Champ: EmptyStr;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+3))
    return EmptyStr;
}
//---------------------------------------------------------------------------
Variant __fastcall TCpChampUser::GetValeur()const
{
    try{
        return m_ConstCpChamp? m_ConstCpChamp->Texte: EmptyStr;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+4))
    return EmptyStr;
}
//---------------------------------------------------------------------------
void __fastcall TCpChampUser::SetValeur( Variant Valeur)
{
    try{
    AnsiString v = Variant(D_NS).operator AnsiString();
        if( m_CpChamp)
            m_CpChamp->Texte = (Valeur.operator AnsiString()==v)?
                            AnsiString(D_NS)
                            :Valeur.operator AnsiString();
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+5))
}
//---------------------------------------------------------------------------
bool __fastcall TCpChampUser::GetVisible()const
{
    try{
        return m_ConstCpChamp? m_ConstCpChamp->Visible: false;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+6))
    return false;
}
//---------------------------------------------------------------------------
void __fastcall TCpChampUser::SetVisible( bool bVisible)
{
    try{
        if( m_CpChamp) m_CpChamp->Visible = bVisible;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+7))
}
short       __fastcall TCpChampUser::GetNumColonneAttachee()const
{
    try{
        if( m_ConstCpChamp && (m_ConstCpChamp->CaracCp & car_LargeurColonne))
            return LOBYTE(m_ConstCpChamp->NumColonne);
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+8))
    return -1;
}
void        __fastcall TCpChampUser::SetNumColonneAttachee( short n)
{
    try{
        if( m_CpChamp && (m_CpChamp->CaracCp & car_LargeurColonne))
            m_CpChamp->NumColonne = MAKEWORD(n, HIBYTE( m_CpChamp->NumColonne));
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+9))
}
short       __fastcall TCpChampUser::GetNbColonneAttachee()const
{
    try{
        if( m_ConstCpChamp && (m_ConstCpChamp->CaracCp & car_LargeurColonne))
            return HIBYTE(m_ConstCpChamp->NumColonne)+1;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+10))
    return 0;
}
void        __fastcall TCpChampUser::SetNbColonneAttachee( short n)
{
    try{
        if( m_CpChamp && (m_CpChamp->CaracCp & car_LargeurColonne))
            m_CpChamp->NumColonne = MAKEWORD(LOBYTE(m_CpChamp->NumColonne), n-1);
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+11))
}
TFont*      __fastcall TCpChampUser::GetFont()const
{
    try{
        return m_Font;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+12))
    return NULL;
}
void        __fastcall TCpChampUser::SetFont( const TFont *f)
{
    try{
        m_Font->Assign( (TFont *)f);
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+13))
}
Text_Presentation  __fastcall TCpChampUser::GetAlignment()const
{
    try{
        return m_ConstCpChamp->Presentation;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+14))
    return (Text_Presentation)0;
}
void        __fastcall TCpChampUser::SetAlignment( Text_Presentation a)
{
    try{
        m_CpChamp->Presentation = a;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+15))
}

TColor      __fastcall TCpChampUser::GetBkColor()const
{
    try{
        return m_ConstCpChamp->BrushColor;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+16))
    return (TColor)0;
}
void        __fastcall TCpChampUser::SetBkColor( TColor c)
{
    try{
        m_CpChamp->BrushColor = c;
        if( c == clNone)
            m_CpChamp->BrushStyle = bsClear;		
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+17))
}
Text_Format __fastcall TCpChampUser::GetTypeFormatage()const
{
    try{
        return m_ConstCpChamp->Format;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+18))
    return (Text_Format)0;
}
void        __fastcall TCpChampUser::SetTypeFormatage( Text_Format f)
{
    try{
        m_CpChamp->Format = f;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+19))
}
int         __fastcall TCpChampUser::GetNumDigits()const
{
    try{
        switch( m_ConstCpChamp->Format)
        {
        case tf_Monetaire : return ((EICCurrencyFmt*)m_ConstCpChamp->pvFormat)->NumDigits;
        case tf_Numerique : return ((EICNumberFmt*)m_ConstCpChamp->pvFormat)->NumDigits;
        default : throw EUser( TAG( DEB_TAG_CHAMP+20), AnsiString("Le format du champ '")+ m_ConstCpChamp->Nom +"' n'est pas numérique");
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+20))
    return 0;
}
#define AffecteFormat( Type, Champ, propriete, valeur)                          \
            if( ((Type*)Champ->pvFormat)->propriete != valeur)                  \
            {                                                                   \
                Champ->CreationFmtNum_Cur();                                    \
                ((Type*)Champ->pvFormat)->propriete = valeur;                   \
            }

void        __fastcall TCpChampUser::SetNumDigits( int i)
{
    try{
        switch( m_CpChamp->Format)
        {
        case tf_Monetaire : AffecteFormat( EICCurrencyFmt, m_CpChamp,  NumDigits, i); break;
        case tf_Numerique : AffecteFormat( EICNumberFmt, m_CpChamp,  NumDigits, i); break;
        default : throw EUser( TAG( DEB_TAG_CHAMP+21), AnsiString("Le format du champ '")+ m_ConstCpChamp->Nom +"' n'est pas numérique");
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+21))
}
float       __fastcall TCpChampUser::GetBordureGauche()const
{
    try{
        return m_ConstCpChamp->PenWidthGauche;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+22))
    return 0;
}
void        __fastcall TCpChampUser::SetBordureGauche( float f)
{
    try{
        m_CpChamp->PenWidthGauche = f;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+23))
}

float       __fastcall TCpChampUser::GetBordureHaute()const
{
    try{
        return m_ConstCpChamp->PenWidthHaut;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+24))
    return 0;
}
void        __fastcall TCpChampUser::SetBordureHaute( float f)
{
    try{
        m_CpChamp->PenWidthHaut = f;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+25))
}
float       __fastcall TCpChampUser::GetBordureDroite()const
{
    try{
        return m_ConstCpChamp->PenWidthDroit;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+26))
    return 0;
}
void        __fastcall TCpChampUser::SetBordureDroite( float f)
{
    try{
        m_CpChamp->PenWidthDroit = f;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+27))
}
float       __fastcall TCpChampUser::GetBordureBasse()const
{
    try{
        return m_ConstCpChamp->PenWidthBas;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+28))
    return 0;
}
void        __fastcall TCpChampUser::SetBordureBasse( float f)
{
    try{
        m_CpChamp->PenWidthBas = f;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+30))
}
int         __fastcall TCpChampUser::GetNbUniteArrondies()const
{
    try{
        switch( m_ConstCpChamp->Format)
        {
        case tf_Monetaire : return ((EICCurrencyFmt*)m_ConstCpChamp->pvFormat)->NbUniteArrondies;
        case tf_Numerique : return ((EICNumberFmt*)m_ConstCpChamp->pvFormat)->NbUniteArrondies;
        default : throw EUser( TAG( DEB_TAG_CHAMP+31), AnsiString("Le format du champ '")+ m_ConstCpChamp->Nom +"' n'est pas numérique");
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+31))
    return 0;
}
void        __fastcall TCpChampUser::SetNbUniteArrondies( int i)
{
    try{
        switch( m_CpChamp->Format)
        {
        case tf_Monetaire : AffecteFormat( EICCurrencyFmt, m_CpChamp,  NbUniteArrondies, i); break;
            /*if( ((EICCurrencyFmt*)m_CpChamp->pvFormat)->NbUniteArrondies != i)
            {
                EICCurrencyFmt* c = (EICCurrencyFmt*)m_CpChamp->pvFormatInterne, *c1;
                if( !c)
                {
                    c = new EICCurrencyFmt();
                    c1 = (EICCurrencyFmt*)m_CpChamp->pvFormat;
                    c->Assign( *c1);
                    m_CpChamp->pvFormat = (TObject*)c;
                }
                ((EICCurrencyFmt*)m_CpChamp->pvFormat)->NbUniteArrondies = i; break;
            }*/
        case tf_Numerique : AffecteFormat( EICNumberFmt, m_CpChamp,  NbUniteArrondies, i); break;
        default : throw EUser( TAG( DEB_TAG_CHAMP+32), AnsiString("Le format du champ '")+ m_ConstCpChamp->Nom +"' n'est pas numérique");
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+32))
}
int __fastcall TCpChampUser::GetRetraitTexte()const
{
  try
  {
    return m_ConstCpChamp->Retrait.DixMm;
  }
  CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+33))
  return 0;
}
void __fastcall TCpChampUser::SetRetraitTexte(int i)
{
    try
    {
      m_CpChamp->Retrait.DixMm = i;
    }
    CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+34))
}
AnsiString  __fastcall TCpChampUser::GetStyle()const
{
  try
  {
    return m_ConstCpChamp->Style;
  }
  CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+35))
  return 0;
}
void __fastcall TCpChampUser::SetStyle(AnsiString s)
{
    try
    {
      m_CpChamp->Style = s;
      m_Font->Assign( m_CpChamp->Font);
    }
    CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+36))
}
bool __fastcall TCpChampUser::GetForceBkStyle()const
{
    try{
        return m_ConstCpChamp->ForceBrushStyle;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+37))
    return bsClear;
}
void __fastcall TCpChampUser::SetForceBkStyle( bool b)
{
    try{
        m_CpChamp->ForceBrushStyle = b;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+38))
}TBrushStyle __fastcall TCpChampUser::GetBkStyle()const
{
    try{
        return m_ConstCpChamp->BrushStyle;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+39))
    return bsClear;
}
void __fastcall TCpChampUser::SetBkStyle( TBrushStyle c)
{
    try{
        m_CpChamp->BrushStyle = c;
    }CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+40))
}
int         __fastcall TCpChampUser::GetZeroSignificatif()const
{
    try{
        switch( m_ConstCpChamp->Format)
        {
        case tf_Monetaire : return ((EICCurrencyFmt*)m_ConstCpChamp->pvFormat)->ZeroSignificatif;
        case tf_Numerique : return ((EICNumberFmt*)m_ConstCpChamp->pvFormat)->ZeroSignificatif;
        default : throw EUser( TAG( DEB_TAG_CHAMP+31), AnsiString("Le format du champ '")+ m_ConstCpChamp->Nom +"' n'est pas numérique");
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+31))
    return 0;
}
void        __fastcall TCpChampUser::SetZeroSignificatif( int i)
{
    try{
        switch( m_CpChamp->Format)
        {
        case tf_Monetaire : AffecteFormat( EICCurrencyFmt, m_CpChamp,  ZeroSignificatif, i); break;
        case tf_Numerique : AffecteFormat( EICNumberFmt, m_CpChamp,  ZeroSignificatif, i); break;
        default : throw EUser( TAG( DEB_TAG_CHAMP+32), AnsiString("Le format du champ '")+ m_ConstCpChamp->Nom +"' n'est pas numérique");
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+32))
}
void __fastcall TCpChampUser::GetAdresse(AnsiString &Denomination, ADRESSE_TDFC &adr)const
{
    try{
        switch( m_CpChamp->Format)
        {
        case tf_Adresse :
          {
            TStringList *Lst = new TStringList();
            Lst->CommaText = Valeur;
            Denomination = ADR_Denomination(Lst).c_str();
            memset( &adr, 0, sizeof( adr));
            strncpy( adr.szCmplAdr1,   ADR_CmplAdr1(Lst).c_str(),   sizeof( adr.szCmplAdr1)-1);
            strncpy( adr.szCmplAdr2,   ADR_CmplAdr2(Lst).c_str(),   sizeof( adr.szCmplAdr2)-1);
            strncpy( adr.szNoVoie,     ADR_NoVoie(Lst).c_str()  ,   sizeof( adr.szNoVoie)-1);
            strncpy( adr.szCmplNoVoie, ADR_CmplNoVoie(Lst).c_str(), sizeof( adr.szCmplNoVoie)-1);
            strncpy( adr.szNomVoie,    ADR_NomVoie(Lst).c_str(),    sizeof( adr.szNomVoie)-1);
            strncpy( adr.szBP,         ADR_BP(Lst).c_str(),         sizeof( adr.szBP)-1);
            strncpy( adr.szCP,         ADR_CP(Lst).c_str(),         sizeof( adr.szCP)-1);
            strncpy( adr.szVille,      ADR_Ville(Lst).c_str(),      sizeof( adr.szVille)-1);
            strncpy( adr.szTel,        ADR_Tel(Lst).c_str(),        sizeof( adr.szTel)-1);
            strncpy( adr.szFAX,        ADR_FAX(Lst).c_str(),        sizeof( adr.szFAX)-1);
            delete Lst;
          }break;
        default : throw EUser( TAG( DEB_TAG_CHAMP+33), AnsiString("Le format du champ '")+ m_ConstCpChamp->Nom +"' n'est pas de type adresse");
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+33))
}
void __fastcall TCpChampUser::SetAdresse( const AnsiString &Denomination, const ADRESSE_TDFC &adr)
{
    try{
        switch( m_CpChamp->Format)
        {
        case tf_Adresse :
          {
            TStringList *Lst = new TStringList();
            Lst->Add( Denomination);
            Lst->Add( adr.szCmplAdr1);
            Lst->Add( adr.szCmplAdr2);
            Lst->Add( adr.szNoVoie);
            if( AnsiCompareText( adr.szCmplNoVoie, "Qua"))
              Lst->Add( adr.szCmplNoVoie);
            else
              Lst->Add( "quater");
            Lst->Add( adr.szNomVoie);
            Lst->Add( adr.szBP);
            Lst->Add( adr.szCP);
            Lst->Add( adr.szVille);
            Lst->Add( adr.szTel);
            Lst->Add( adr.szFAX);
            Valeur = Lst->CommaText;
            delete Lst;
          }break;
        default : throw EUser( TAG( DEB_TAG_CHAMP+34), AnsiString("Le format du champ '")+ m_ConstCpChamp->Nom +"' n'est pas de type adresse");
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+34))
}
Type_Champ  __fastcall TCpChampUser::GetType()const
{
  try
  {
    return m_ConstCpChamp->Type;
  }
  CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+37))
  return tc_Normal;
}
void __fastcall TCpChampUser::SetType(Type_Champ t)
{
  try
  {
    m_CpChamp->Type = t;
  }
  CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+36))
}
AnsiString __fastcall TCpChampUser::GetFormule()const
{
  try
  {
    return m_ConstCpChamp->Formule;
  }
  CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+37))
  return EmptyStr;
}
void __fastcall TCpChampUser::SetFormule(AnsiString s)
{
  try
  {
    m_CpChamp->Formule = s;
  }
  CATCH_EXCEPTION( TAG( DEB_TAG_CHAMP+38))
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------   TTableauUser   --------------------------------
//---------------------------------------------------------------------------
__fastcall TCpTableauUser::~TCpTableauUser( )
{
    try{
        delete m_BandeProprietaire;
    }CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU))
}
__fastcall TCpTableauUser::TCpTableauUser( TCpTableau* CpTableau):TObject()
{
    try{
        m_CpTableau           = CpTableau;
        m_BandeProprietaire = new TBandeUser( CpTableau->BandeHt);
    }CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+1))
}
AnsiString __fastcall TCpTableauUser::GetNom()const
{
    try{
        return m_CpTableau? m_CpTableau->Nom: EmptyStr;
    }CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+2))
    return EmptyStr;
}
bool   __fastcall TCpTableauUser::GetVisible( short nCol)const
{
    try{
        if( !m_CpTableau) return false;
        COLONNE* c = m_CpTableau->GetColonne( nCol, false);
        if( !c) throw EUser( TAG( DEB_TAG_TABLEAU+3), "Colonne inexistante");
        return c->Visible;
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+3))
    return false;
}
void   __fastcall TCpTableauUser::SetVisible( short nCol, bool b)
{
    try{
        if( !m_CpTableau) return;
        COLONNE* c = m_CpTableau->GetColonne( nCol, false);
        if( !c) throw EUser( TAG( DEB_TAG_TABLEAU+4), "Colonne inexistante");
        if( c->Visible != b)
        {
            c->Visible = b;
            m_CpTableau->Nettoie();
            m_CpTableau->EtatOwner->InvalideComposantsAttacheA( m_CpTableau->Nom);
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+4))
}
int   __fastcall TCpTableauUser::GetLargeur( short nCol)const
{
    try{
        if( !m_CpTableau) return false;
        COLONNE* c = m_CpTableau->GetColonne( nCol, false);
        if( !c) throw EUser( TAG( DEB_TAG_TABLEAU+5), "Colonne inexistante");
        return c->LargeurSaisie.DixMm;
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+5))
    return 0;
}
void   __fastcall TCpTableauUser::SetLargeur( short nCol, int n)
{
    try{
        if( !m_CpTableau) return;
        COLONNE* c = m_CpTableau->GetColonne( nCol, false);
        if( !c) throw EUser( TAG( DEB_TAG_TABLEAU+6), "Colonne inexistante");
        if( c->LargeurSaisie.DixMm != n)
        {
            c->LargeurSaisie.DixMm = n;
            m_CpTableau->Nettoie();
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+6))
}
int   __fastcall TCpTableauUser::GetOrdreAffichage( short nCol)const
{
    try{
        if( !m_CpTableau) return 0;
        COLONNE* c = m_CpTableau->GetColonne( nCol, false);
        if( !c) throw EUser( TAG( DEB_TAG_TABLEAU+7), "Colonne inexistante");
        return c->nOrdreAffichage;
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+7))
    return 0;
}
void   __fastcall TCpTableauUser::SetOrdreAffichage( short nCol, int n)
{
    try{
        if( !m_CpTableau) return;
        COLONNE* c = m_CpTableau->GetColonne( nCol, false);
        if( !c) throw EUser( TAG( DEB_TAG_TABLEAU+8), "Colonne inexistante");
        if( c->nOrdreAffichage != n)
        {
            c->nOrdreAffichage = n;
            m_CpTableau->Nettoie();
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+8))
}
int    __fastcall TCpTableauUser::GetNbCol( )const
{
    try{
        if( !m_CpTableau) return 0;
        return m_CpTableau->ColonnesCount;
    }CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+9))
    return 0;
}
int    __fastcall TCpTableauUser::GetLargeurMin( short nCol)const
{
    try{
        if( !m_CpTableau) return false;
        COLONNE* c = m_CpTableau->GetColonne( nCol, false);
        if( !c) throw EUser( TAG( DEB_TAG_TABLEAU+10), "Colonne inexistante");
        return c->LargeurMin.DixMm;
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+10))
    return 0;
}
void   __fastcall TCpTableauUser::SetLargeurMin( short nCol, int n)
{
    try{
        if( !m_CpTableau) return;
        COLONNE* c = m_CpTableau->GetColonne( nCol, false);
        if( !c) throw EUser( TAG( DEB_TAG_TABLEAU+11), "Colonne inexistante");
        if( c->LargeurMin.DixMm != n)
        {
            c->LargeurMin.DixMm = n;
            m_CpTableau->Nettoie();
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+11))
}
int    __fastcall TCpTableauUser::GetLargeurMax( short nCol)const
{
    try{
        if( !m_CpTableau) return false;
        COLONNE* c = m_CpTableau->GetColonne( nCol, false);
        if( !c) throw EUser( TAG( DEB_TAG_TABLEAU+12), "Colonne inexistante");
        return c->LargeurMax.DixMm;
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+12))
    return 0;
}
void   __fastcall TCpTableauUser::SetLargeurMax( short nCol, int n)
{
    try{
        if( !m_CpTableau) return;
        COLONNE* c = m_CpTableau->GetColonne( nCol, false);
        if( !c) throw EUser( TAG( DEB_TAG_TABLEAU+13), "Colonne inexistante");
        if( c->LargeurMax.DixMm != n)
        {
            c->LargeurMax.DixMm = n;
            m_CpTableau->Nettoie();
        }
    }catch( EUser &e){ throw;}
    CATCH_EXCEPTION( TAG( DEB_TAG_TABLEAU+13))
}
//-------------------------------------------------------------------------------------
void PACKAGE_PCKETAT __fastcall InitLstStyles( EICListStyle **pLstStylesModif, TDocUser *Doc, TMemoryStream* s)
{
  TFlux *f = NULL;
  bool   bListExist = (*pLstStylesModif);
  try
  {
    EtatInitialize(gVersionDeDemonstration);

    f = NewTFlux();
    ASSERT( Doc || s);

    if( s)
    {
      TMemoryStream* sOld = ((TMemoryStream*)(f->s));
      try
      {
        DWORD FileVersion;
        ((TMemoryStream*)(f->s)) = s;
        ((TMemoryStream*)(f->s))->Position = 0;
        if( !bListExist) (*pLstStylesModif) = NewEICListStyle();
        f->Lit( FileVersion);
        f->FileVersion = FileVersion;
        (*pLstStylesModif)->Lit( f);
        ((TMemoryStream*)(f->s)) = sOld;
      }
      catch( EDocException &e)
      {
        ((TMemoryStream*)(f->s)) = sOld;
        if( !bListExist) { DeleteEICListStyle (*pLstStylesModif); (*pLstStylesModif) = NULL; }
        if( Doc) Doc->GetLstStylesDoc( pLstStylesModif);
        throw;
      }
    }
    else if( Doc) Doc->GetLstStylesDoc( pLstStylesModif);
  }
  catch( EDocException &e){ DeleteTFlux( f); throw;}
  catch( Exception &e)
  {
    EICDisplayException(TAGL,e);
  }
  DeleteTFlux( f);

  EtatUnInitialize();
}
//-------------------------------------------------------------------------------------
void PACKAGE_PCKETAT __fastcall EnregistreLstStyles( EICListStyle **pLstStylesModif, TMemoryStream* s)
{
  TFlux *f = NULL;
  try
  {
    if( *pLstStylesModif)
    {
      f = NewTFlux();
      TMemoryStream* sOld = ((TMemoryStream*)(f->s));
      ((TMemoryStream*)(f->s)) = s;
      f->Ecrit( CUR_VER_FILE);
      (*pLstStylesModif)->Enregistre( f);
      ((TMemoryStream*)(f->s)) = sOld;
    }
  }
  catch( Exception &e)
  {
    EICDisplayException(TAGL,e);
  }
  DeleteTFlux( f);
}
//-------------------------------------------------------------------------------------
void PACKAGE_PCKETAT __fastcall AfficherStyles( TComponent* Owner, EICListStyle *pLstStyles)
{
  AfficheStyles( Owner, pLstStyles);
}
//-------------------------------------------------------------------------------------
void PACKAGE_PCKETAT __fastcall DetruireLstStylesModif( EICListStyle *pLstStylesModif)
{
  DestroyLstStylesModif( (TStringList *)pLstStylesModif);
}
//-------------------------------------------------------------------------------------

